package com.health.manage.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.health.manage.mapper.EducationMapper;
import com.health.manage.mapper.UserMapper;
import com.health.manage.pojo.dto.EducationDto;
import com.health.manage.pojo.entity.Education;
import com.health.manage.pojo.entity.Medical;
import com.health.manage.pojo.entity.User;
import com.health.manage.service.IEducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 *
 * @Description: 教育业务处理
 * @author: medical
 */
@Service
public class EducationServiceImpl extends ServiceImpl<EducationMapper, Education> implements IEducationService {

	@Autowired(required = false)
	private EducationMapper medicalMapper;
	@Autowired(required = false)
	private UserMapper userMapper;

	@Override
	public Boolean addData(Education medical) {
		int result = this.medicalMapper.insert(medical);
		if(result > 1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public Boolean updateData(Education medical) {
		int result = this.medicalMapper.updateById(medical);
		if(result > 1){
			return true;
		}else{
			return false;
		}
	}


	@Override
	public Boolean deleteData(Long id) {
		int result = this.medicalMapper.deleteById(id);
		if(result > 1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public Page<Education> getPageData(EducationDto medicalDto) {

		Page<Education> page = new Page<>(medicalDto.getCurrentPage(), medicalDto.getPageSize());
		QueryWrapper<Education> queryWrapper = new QueryWrapper<>();
		if(medicalDto.getKnowledge()!=null && !"".equals(medicalDto.getKnowledge())){
			queryWrapper.like("knowledge", medicalDto.getKnowledge());
		}
		Page<Education>records = this.medicalMapper.selectPage(page, queryWrapper);
		for(Education education : records.getRecords()){
			User creator = this.userMapper.selectById(education.getCreateId());
			if(creator != null){
				education.setCreator(creator);
			}
		}
		return records;
	}


}
